<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label=":">
        <el-input v-model="queryParams.seq" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.mon" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.tue" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.wed" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.thu" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.fri" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sat" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sun" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.nian" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.zhou" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.yue" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.firstdayat" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sundaydate" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.version" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.shipperCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.monP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.tueP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.wedP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.thuP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.friP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.satP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sunP" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.monCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.tueCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.wedCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.thuCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.thuCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.wedCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.tueCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.monCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.friCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.friCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.satCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.satCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sunCt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.sunCo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间:">
        <el-date-picker v-model="queryParams.createDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择创建时间" clearable />
      </el-form-item>
      <el-form-item label="更新时间:">
        <el-date-picker v-model="queryParams.updateDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择更新时间" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:myCalendar:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:myCalendar:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:myCalendar:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:myCalendar:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="seq" />
      <el-table-column label="" align="center" prop="mon" />
      <el-table-column label="" align="center" prop="tue" />
      <el-table-column label="" align="center" prop="wed" />
      <el-table-column label="" align="center" prop="thu" />
      <el-table-column label="" align="center" prop="fri" />
      <el-table-column label="" align="center" prop="sat" />
      <el-table-column label="" align="center" prop="sun" />
      <el-table-column label="" align="center" prop="nian" />
      <el-table-column label="" align="center" prop="zhou" />
      <el-table-column label="" align="center" prop="yue" />
      <el-table-column label="" align="center" prop="firstdayat" />
      <el-table-column label="" align="center" prop="sundaydate" />
      <el-table-column label="" align="center" prop="version" />
      <el-table-column label="" align="center" prop="shipperCode" />
      <el-table-column label="" align="center" prop="monP" />
      <el-table-column label="" align="center" prop="tueP" />
      <el-table-column label="" align="center" prop="wedP" />
      <el-table-column label="" align="center" prop="thuP" />
      <el-table-column label="" align="center" prop="friP" />
      <el-table-column label="" align="center" prop="satP" />
      <el-table-column label="" align="center" prop="sunP" />
      <el-table-column label="" align="center" prop="monCt" />
      <el-table-column label="" align="center" prop="tueCt" />
      <el-table-column label="" align="center" prop="wedCt" />
      <el-table-column label="" align="center" prop="thuCt" />
      <el-table-column label="" align="center" prop="thuCo" />
      <el-table-column label="" align="center" prop="wedCo" />
      <el-table-column label="" align="center" prop="tueCo" />
      <el-table-column label="" align="center" prop="monCo" />
      <el-table-column label="" align="center" prop="friCo" />
      <el-table-column label="" align="center" prop="friCt" />
      <el-table-column label="" align="center" prop="satCt" />
      <el-table-column label="" align="center" prop="satCo" />
      <el-table-column label="" align="center" prop="sunCt" />
      <el-table-column label="" align="center" prop="sunCo" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['basic:myCalendar:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['basic:myCalendar:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="myCalendarFormDialog.title" :visible.sync="myCalendarFormDialog.visible" :close-on-click-modal="false" :before-close="resetMyCalendarFormDialog" width="500px" append-to-body>
      <el-form ref="myCalendarForm" :model="myCalendarFormData" :rules="myCalendarFormRules" label-width="80px">
        <el-form-item label="" prop="seq">
          <el-input v-model="myCalendarFormData.seq" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="mon">
          <el-input v-model="myCalendarFormData.mon" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="tue">
          <el-input v-model="myCalendarFormData.tue" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="wed">
          <el-input v-model="myCalendarFormData.wed" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="thu">
          <el-input v-model="myCalendarFormData.thu" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="fri">
          <el-input v-model="myCalendarFormData.fri" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sat">
          <el-input v-model="myCalendarFormData.sat" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sun">
          <el-input v-model="myCalendarFormData.sun" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="nian">
          <el-input v-model="myCalendarFormData.nian" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zhou">
          <el-input v-model="myCalendarFormData.zhou" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="yue">
          <el-input v-model="myCalendarFormData.yue" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="firstdayat">
          <el-input v-model="myCalendarFormData.firstdayat" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sundaydate">
          <el-input v-model="myCalendarFormData.sundaydate" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="version">
          <el-input v-model="myCalendarFormData.version" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="shipperCode">
          <el-input v-model="myCalendarFormData.shipperCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="monP">
          <el-input v-model="myCalendarFormData.monP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="tueP">
          <el-input v-model="myCalendarFormData.tueP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="wedP">
          <el-input v-model="myCalendarFormData.wedP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="thuP">
          <el-input v-model="myCalendarFormData.thuP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="friP">
          <el-input v-model="myCalendarFormData.friP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="satP">
          <el-input v-model="myCalendarFormData.satP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sunP">
          <el-input v-model="myCalendarFormData.sunP" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="monCt">
          <el-input v-model="myCalendarFormData.monCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="tueCt">
          <el-input v-model="myCalendarFormData.tueCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="wedCt">
          <el-input v-model="myCalendarFormData.wedCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="thuCt">
          <el-input v-model="myCalendarFormData.thuCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="thuCo">
          <el-input v-model="myCalendarFormData.thuCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="wedCo">
          <el-input v-model="myCalendarFormData.wedCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="tueCo">
          <el-input v-model="myCalendarFormData.tueCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="monCo">
          <el-input v-model="myCalendarFormData.monCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="friCo">
          <el-input v-model="myCalendarFormData.friCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="friCt">
          <el-input v-model="myCalendarFormData.friCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="satCt">
          <el-input v-model="myCalendarFormData.satCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="satCo">
          <el-input v-model="myCalendarFormData.satCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sunCt">
          <el-input v-model="myCalendarFormData.sunCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="sunCo">
          <el-input v-model="myCalendarFormData.sunCo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker v-model="myCalendarFormData.createDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择创建时间" clearable />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker v-model="myCalendarFormData.updateDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择更新时间" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmMyCalendarFormDialog">确 定</el-button>
        <el-button @click="resetMyCalendarFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import MyCalendarApi from '@/api/basic/MyCalendarApi'

const defaultMyCalendarFormData = {
  seq: null,  mon: null,  tue: null,  wed: null,  thu: null,  fri: null,  sat: null,  sun: null,  nian: null,  zhou: null,  yue: null,  firstdayat: null,  sundaydate: null,  version: null,  shipperCode: null,  monP: null,  tueP: null,  wedP: null,  thuP: null,  friP: null,  satP: null,  sunP: null,  monCt: null,  tueCt: null,  wedCt: null,  thuCt: null,  thuCo: null,  wedCo: null,  tueCo: null,  monCo: null,  friCo: null,  friCt: null,  satCt: null,  satCo: null,  sunCt: null,  sunCo: null,  createDate: null,  updateDate: null,}
export default {
  name: 'MyCalendarList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        seq: null,
        mon: null,
        tue: null,
        wed: null,
        thu: null,
        fri: null,
        sat: null,
        sun: null,
        nian: null,
        zhou: null,
        yue: null,
        firstdayat: null,
        sundaydate: null,
        version: null,
        shipperCode: null,
        monP: null,
        tueP: null,
        wedP: null,
        thuP: null,
        friP: null,
        satP: null,
        sunP: null,
        monCt: null,
        tueCt: null,
        wedCt: null,
        thuCt: null,
        thuCo: null,
        wedCo: null,
        tueCo: null,
        monCo: null,
        friCo: null,
        friCt: null,
        satCt: null,
        satCo: null,
        sunCt: null,
        sunCo: null,
        createDate: null,
        updateDate: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      myCalendarFormDialog: {
        title: '',
        visible: false
      },
      myCalendarFormData: Object.assign({}, defaultMyCalendarFormData),
      myCalendarFormRules: {
        createDate: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
        updateDate: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openMyCalendarFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return MyCalendarApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openMyCalendarFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      MyCalendarApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return MyCalendarApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openMyCalendarFormDialog(id) {
      this.myCalendarFormDialog.visible = true
      if (id) {
        this.myCalendarFormDialog.title = '业务汇总日历-修改'
        MyCalendarApi.get(id).then(response => {
          this.myCalendarFormData = {
            ...this.myCalendarFormData,
            ...response.data
          }
        })
      } else {
        this.myCalendarFormDialog.title = '业务汇总日历-添加'
      }
    },
    confirmMyCalendarFormDialog() {
      this.$refs['myCalendarForm'].validate(valid => {
        if (valid) {
          if (this.myCalendarFormData.id) {
            MyCalendarApi.edit(this.myCalendarFormData).then(response => {
              this.$message.success('修改成功')
              this.resetMyCalendarFormDialog()
              this.handleQuery()
            })
          } else {
            MyCalendarApi.add(this.myCalendarFormData).then(response => {
              this.$message.success('添加成功')
              this.resetMyCalendarFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetMyCalendarFormDialog() {
      this.myCalendarFormDialog = {
        title: '',
        visible: false
      }
      this.myCalendarFormData = Object.assign({}, defaultMyCalendarFormData)
      this.resetForm('myCalendarForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
